package com.guoju.tyframework.mvc.context;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.jdom.JDOMException;

import com.guoju.tyframework.mvc.ServletConstants;
import com.guoju.tyframework.mvc.config.ActionConfiguration;
import com.guoju.tyframework.mvc.providers.ActionXmlProvider;
import com.guoju.tyframework.mvc.utils.ServletUtil;


public class ActionListener implements ServletContextListener{

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {

		System.out.println("---监听销毁---");
		
	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		System.out.println("--listenerBeginning--");
		ServletContext context=arg0.getServletContext();
		String xmlPath=ServletUtil.getXmlFilePath(context);
		try {
			Map<String,ActionConfiguration> map=ActionXmlProvider.doResolve(xmlPath);
			context.setAttribute(ServletConstants.CONTEXT_ACTION_CONFIG, map);
		} catch (JDOMException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}

	
}
